﻿Imports System.Data
Imports VSModel
Imports Cls_Common
Partial Class FrontEnd_Control_Store_Footer
    Inherits System.Web.UI.UserControl
    Public curURL As String = ""
    Public curStoreURL As String = ""
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            If Not Page.IsPostBack Then
                If Not Page.RouteData.Values("Id") Is Nothing Then
                    loadHeader(Page.RouteData.Values("Id"))
                    LoadMenu(Page.RouteData.Values("Id"))
                End If
            End If

        End If
    End Sub
    Protected Sub loadHeader(ByVal StoreId As Integer)

        Using data As New VSEntities
            Dim p = (From q In data.Stores Where q.StoreId = StoreId Select q).FirstOrDefault
            If Not p Is Nothing Then
                curStoreURL = MainDomain & p.QueryString & "-" & p.StoreId & "/"
            End If
        End Using
    End Sub
    Protected Sub LoadMenu(ByVal StoreId As Integer)

        curURL = Request.Url.AbsoluteUri.ToString.Replace(MainDomain, "").Split("/")(1).Replace(".html", "") & ".html"

        Dim lstNode As New DataSet
        lstNode.ReadXml(MapPath("../../../xml/HeaderStoreMenu.xml"))
        With rptMenu
            .DataSource = lstNode.Tables("Node")
            .DataBind()
        End With
    End Sub
    Protected Sub rptMenu_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptMenu.ItemDataBound
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
        hplTitle.NavigateUrl = curStoreURL & e.Item.DataItem("URL").ToString
        hplTitle.Text = e.Item.DataItem("Title")
    End Sub
End Class
